home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / tcp / rxmiamibpf.lha / rxmiamibpf / examples / bomon.rexx next >
Encoding:
OS/2 REXX Batch file  |  1998-10-22  |  1.8 KB  |  88 lines

  1. /* */
  2.  
  3. signal on break_c
  4.  
  5. /*LIBRARIES*/
  6. if ~show("L","rmh.library") then
  7.     if ~addlib("rmh.library",0,-30) then do
  8.         say "no rmh.library"
  9.         exit
  10.     end
  11. if ~show("L","rxsocket.library") then
  12.     if ~addlib("rxsocket.library",0,-30) then do
  13.         say "no rxsocket.library"
  14.         exit
  15.     end
  16. if ~show("L","rxmiamibpf.library") then
  17.     if ~addlib("rxmiamibpf.library",0,-30) then do
  18.         say "no rxmiamibpf.library"
  19.         exit
  20.     end
  21.  
  22. /*ARGUMENTS*/
  23. prg=ProgramName("NOEXT")
  24. if ~RMH_ReadArgs("INTERFACE") then do
  25.     call PrintFault(IoErr(),prg)
  26.     exit
  27. end
  28.  
  29. if parm.0.flag then do
  30.     interface=parm.0.value
  31.     res=IsOnLine(parm.0.value)
  32.     if res<0 then call err "interface '"interface"' doesn't exist"
  33.     if res==0 then call err "interface '"interface"' is not up"
  34. end
  35. else interface=""
  36.  
  37. ctrlc=2**12
  38. bpfa.device    = interface
  39. bpfa.BuffLen   = 256
  40. bpfa.Immediate = 1
  41. bpfa.AbortMask = ctrlc
  42. bpfa.Filter    = "udp and dst port 31337"
  43. bpf=MiamiBPFOpen("BPFA")
  44. if bpf<0 then call err BPFERR
  45.  
  46. call MiamiBPFIoctlGet(bpf,"D","DEVICE")
  47. say "Listening for BackOrifice connection on device: '"d"'"
  48.  
  49. cs = MiamiBPFSignalmask(bpf)
  50. call MiamiBPFSetAbortMask(bpf,ctrlc)
  51. sig=or(cs,ctrlC)
  52.  
  53. do while 1
  54.     call MiamiBPFIoctlGet(bpf,"BS","FIONREAD")
  55.     if bs<=0 then res=Wait(sig)
  56.     else if CheckSignal(ctrlc) then res = ctrlc
  57.          else res=0
  58.     if and(res,ctrlc)~=0 then signal break_c
  59.     call MiamiBPFIoctlGet(bpf,"BS","FIONREAD")
  60.     if bs>0 then do
  61.         l=MiamiBPFRead(bpf,"PKT")
  62.         if l>0 then call parsePkt(pkt)
  63.     end
  64. end
  65.  
  66. rresolve: procedure
  67. parse arg ip
  68.     if ~GethostByAddr("H",ip) then return ip
  69.     return h.hostname
  70.  
  71. parsepkt:
  72. parse arg pkt
  73.  
  74.     call ReadIP(pkt,"IPH")
  75.     call readUDP(substr(pkt,21,100),"UDPH")
  76.     from=rresolve(iph.src)
  77.     fromPort=udph.sport
  78.     call SysLog("BackOrifice connection from ["from":"fromPort"]")
  79.     return
  80.  
  81. break_c:
  82.     exit
  83.  
  84. err: procedure expose prg
  85. parse arg msg
  86.     say prg":" msg
  87.     exit
  88.